<template>
  <div
    class="organizationLibrary"
    v-loading="$store.getters.loading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="#a19f9fb0;"
  >
    <lb-layout>
      <aps-form
        :config="apsForm.formConfig"
        :model="apsForm.formData"
        :formRef="apsForm.formRef"
        :labelWidth="apsForm.labelWidth"
        ref="form"
      ></aps-form>
      <lb-table
        :column="tableData.column"
        :data="tableData.data"
        pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :page-sizes="[20, 40, 60, 80]"
        :pager-count="5"
        :current-page.sync="currentPage"
        :total="total"
        :page-size="pageSize"
        @size-change="handleSizeChange"
        @p-current-change="handleCurrentChange"
        @selection-change="handleSelectionChange"
        class="addCourseTypeTable"
      >
      </lb-table>
    </lb-layout>
  </div>
</template>

<script>
import { getInstitutionslist } from "@/api/standingbook/common.js";

export default {
  name: "organizationLibrary",
  dicts: [
    "organization_catagroy",
    "organization_type",
    "reporting_status",
    "administrative_division",
  ],
  data() {
    return {
      versionNumberlist: [],
      apsForm: {
        formRef: "form",
        labelWidth: "120px",
        formData: {},
        formConfig: {
          formAttr: {
            inline: true,
            size: "small",
          },
          properties: {
            // organizationStructureCode: {
            //   typeName: "el-input",
            //   placeholder: "请输入组织结构代码",
            // },
            unifiedSocialCreditCode: {
              typeName: "el-input",
              placeholder: "请输入信用代码",
            },
            companyName: {
              typeName: "el-input",
              placeholder: "请输入机构名称",
            },
          },
          formSoltButton: [
            {
              label: "搜索",
              type: "primary",
              typeName: "el-button",
              size: "small",
              icon: "el-icon-search",
              click: this.handlerSearchDetail,
            },
            {
              label: "重置",
              typeName: "el-button",
              size: "small",
              icon: "el-icon-refresh-left",
              click: this.handleReset,
            },
          ],
        },
      },
      tableData: {
        column: [
          // {
          //   type: "selection",
          // },
          {
            prop: "companyName",
            label: "机构名称",
            showOverflowTooltip: true,
          },
          {
            prop: "organizationType",
            label: "机构类型",
            width: "150",
            render: (h, scope) => {
              return (
                <div>
                  <dict-tag
                    options={this.dict.type.organization_type}
                    value={scope.row.organizationType}
                  />
                </div>
              );
            },
          },
          {
            prop: "administrativeDivision",
            label: "行政区划",
            width: "150",
            render: (h, scope) => {
              return (
                <div>
                  <dict-tag
                    options={this.dict.type.administrative_division}
                    value={scope.row.administrativeDivision}
                  />
                </div>
              );
            },
          },
          // {
          //   prop: "organizationStructureCode",
          //   label: "组织结构代码",
          //   width: "150",
          // },
          {
            prop: "unifiedSocialCreditCode",
            label: "统一社会信用代码",
            width: "220",
          },
          {
            prop: "",
            label: "单位地址",
            width: "350",
            render: (h, scope) => {
              let a = "";
              let p1 =
                scope.row.companyAddressProvince == null
                  ? ""
                  : scope.row.companyAddressProvince;
              let p2 =
                scope.row.companyAddressCity == null
                  ? ""
                  : scope.row.companyAddressCity;
              let p3 =
                scope.row.companyAddressCounty == null
                  ? ""
                  : scope.row.companyAddressCounty;
              let p4 =
                scope.row.companyAddressTown == null
                  ? ""
                  : scope.row.companyAddressTown;
              let p5 =
                scope.row.companyAddressStreet == null
                  ? ""
                  : scope.row.companyAddressStreet;
              let p6 =
                scope.row.companyAddressHouseNum == null
                  ? ""
                  : scope.row.companyAddressHouseNum;
              a = p1 + p2 + p3 + p4 + p5 + p6;
              return h("div", {}, a);
            },
          },
          {
            prop: "phone",
            label: "联系电话",
            width: "150",
          },
          {
            prop: "status",
            label: "状态",
            width: "120",
            render: (h, scope) => {
              return (
                <div>
                  <dict-tag
                    options={this.dict.type.reporting_status}
                    value={scope.row.status}
                  />
                </div>
              );
            },
            // render: (h, scope) => {
            //   let testType = scope.row.status;
            //   let typeArr = this.dict.type.reporting_status;
            //   let typeName = "";
            //   typeArr.forEach((element) => {
            //     if (element.value == testType) {
            //       typeName = element.label;
            //     }
            //   });
            //   return h("div", {}, typeName);
            // },
          },
        ],
        data: [],
      },
      currentPage: 1,
      pageSize: 20,
      total: 0,
      multipleSelection: [],
    };
  },
  created() {},
  mounted() {
    this.initData();
  },
  methods: {
    async initData(currentPage, pageSize, data) {
      let that = this;
      let query = {};
      if (currentPage) {
        query.pageNum = currentPage;
      } else {
        query.pageNum = that.currentPage;
      }
      if (pageSize) {
        query.pageSize = pageSize;
      } else {
        query.pageSize = that.pageSize;
      }
      if (data) {
        // query.organizationStructureCode =
        //   data?.organizationStructureCode ?? null;
        query.unifiedSocialCreditCode = data?.unifiedSocialCreditCode ?? null;
        query.companyName = data?.companyName ?? null;
      }
      this.$store.commit("app/updateApiCount", "add");
      await getInstitutionslist(query)
        .then((res) => {
          // console.log(res, "列表");
          this.$store.commit("app/updateApiCount");
          if (res.code === 700) {
            that.$message.warning(res.msg);
            return false;
          }
          that.tableData.data = res.rows;
          that.total = res.total;
        })
        .catch((err) => {
          this.$store.commit("app/updateApiCount");
          // this.$message.error("系统错误,请联系管理员!20070");
        });
    },
    handlerSearchDetail(val) {
      //val===1 删除操作成功后分页边界值处理
      let data = {};
      let currentPage = 1;
      if (val === 1) {
        if (
          this.total === (this.currentPage - 1) * this.pageSize + 1 &&
          this.total !== 0 &&
          this.currentPage > 1
        ) {
          currentPage = this.currentPage - 1;
          this.currentPage = currentPage;
        } else {
          currentPage = this.currentPage;
        }
      } else {
        currentPage = this.currentPage;
      }
      // data.organizationStructureCode =
      //   this.$refs?.form?.getFieldsValue().organizationStructureCode;
      data.unifiedSocialCreditCode =
        this.$refs?.form?.getFieldsValue().unifiedSocialCreditCode;
      data.companyName = this.$refs?.form?.getFieldsValue().companyName;
      this.initData(currentPage, this.pageSize, data);
    },
    handleSizeChange(val) {
      this.currentPage = 1;
      this.pageSize = val;
      this.handlerSearchDetail();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.handlerSearchDetail();
    },
    handleReset() {
      //重置
      this.$refs?.form?.resetFields();
      this.handlerSearchDetail();
    },
    // 多选
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
  },
};
</script>

<style scoped lang="scss">
.organizationLibrary {
  width: 100%;
}
</style>


